<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2017-7-21
 * Func   香港时时彩
 */
defined('IN_YuLin') || exit('NO PERMIT!');

//	计算两个值：money（投注金额），orders（订单数组），plays（玩法）
$money = 0;
$orders = [];
$plays = [];

foreach($nums as $val)
{	
	$playid = intval($val['id']);
	if(!$playid)
	{
		continue;
	}
	
	$tmp = $db->getrow('SELECT * FROM '.$ptable.' WHERE playid = '.$playid.' AND status = 1 AND cid = '.$cid);
	if(!$tmp)
	{
		continue;
	}
	$plays[] = $tmp;
	$rateforce && $val['odds'] = $tmp['maxprize'];	//	按照最新赔率来
	
	//	连码：503,504,505
	//	一肖：508,511,512,513,514,515,516,517,518,519,520
	//	不中：523,524,525,526,527,528,529,530
	//	连肖：532,533,534,535
	//	连尾：536,537,538,539,540,541
	if(in_array($tmp['parentid'],[503,504,505,508,511,512,513,514,515,516,517,518,519,520,523,524,525,526,527,528,529,530,532,533,534,535,536,537,538,539,540,541]))
	{
		$tmp2 = explode(',',$val['goal']);
		
		$val['goal'] = [];
		foreach($tmp2 as $t2)
		{
			$t2 = intval($t2);
			if($t2)
			{
				$t2 = $db->getrow('SELECT name FROM '.$ptable.' WHERE playid = '.$t2.' AND status = 1 AND cid = '.$cid);
				$t2 && $val['goal'][] = $t2['name'];
			}
		}
		
		if(!$val['goal'])
		{
			continue;
		}
		
		$val['goal'] = implode(',',$val['goal']);
	}
	else
	{
		$val['goal'] = $plays['name'];	//	奖号
	}
	
	//	单位1、2、3对应元角分
	$unit = intval($val['m']);
	$units = [1=>1,2=>0.1,3=>0.01];
	!array_key_exists($unit,$units) && $unit = 1;
	
	//	赔率
	$odds = max(0,round($val['odds'],2));
	
	//	注数
	$multiple = 1;
	
	//	倍数
	$times = 1;
	
	//	金额
	$money2 = round($val['amount'],2);
	if($money2 <= 0)
	{
		continue;
	}
	
	//	彩票号
	$rednum = NoBadStr($val['goal']);
	if(!$rednum)
	{
		continue;
	}
	
	$ins = [];
	$ins['uid']		=	$_uid;
	$ins['cid']		=	$cid;
	$ins['iid']		=	$iid;
	$ins['pid']		=	$playid;
	$ins['period']	=	$period;
	$ins['rednum']	=	$rednum;
	$ins['times']	=	$times;
	$ins['multiple']=	$multiple;
	$ins['odds']	=	$odds;
	$ins['unit']	=	$unit;
	$ins['money']	=	$money2;//$multiple * $times * 2 * $units[$unit];
	$ins['dateline']=	TIMESTAMP;
	$orders[] = $ins;
	
	$money += $ins['money'];
}
